package com.atguigu.gmall.mq.controller;

import com.atguigu.gmall.common.config.DeadLetterConfig;
import com.atguigu.gmall.common.config.DelayedConfig;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.service.RabbitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author gsy
 * @date 2021年09月12日20:45
 * Description
 */
@RestController
public class SendMessageController {

    @Autowired
    private RabbitService rabbitService;
    //发送消息
    @GetMapping("/sendMessage/{message}")
    public Result sendMessage(@PathVariable String message){

        rabbitService.sendMessage("exchange123","rount123",message);
        return Result.ok();
    }
    //发送延迟消息 基于死信
    @GetMapping("/sendDeadLetterMessage/{message}")
    public Result sendDeadLetterMessage(@PathVariable String message){

        rabbitService.sendDeadLetterMessage(DeadLetterConfig.exchange_dead,DeadLetterConfig.routing_dead_1,message,8);
        return Result.ok();
    }

    //发送延迟消息 基于插件
    @GetMapping("/sendDelayedMessage/{message}")
    public Result sendDelayedMessage(@PathVariable String message){

        rabbitService.sendDelayedMessage(DelayedConfig.exchange_delay,DelayedConfig.routing_delay,message,9);
        return Result.ok();
    }
}
